/*
 * File:   editTaskWindow.cpp
 * Author: switch
 *
 * Created on 16 février 2013, 11:56
 */

#include "editTaskWindow.h"

editTaskWindow::editTaskWindow(accueil *parent, Task* editTask) {
    widget.setupUi(this);
    
    parent_=parent;
    editTask_=editTask;
    
    
    widget.taskName->insert(QString(editTask_->getTitre().c_str()));
    
    widget.checkBoxOrdo->setChecked(editTask_->isOrdo());
    
    if(editTask_->isOrdo()) {
        widget.number->setValue(editTask_->getNumber());
    }
    
    widget.checkBoxEcheance->setChecked(editTask_->isEcheance());
    
    if(editTask_->isEcheance()) {
        widget.comboEcheance->setCurrentIndex(atoi(editTask_->getDeadLine().substr(0,1).c_str())-1);
    }
    
    QObject::connect(widget.editTaskBtn, SIGNAL(clicked()), this, SLOT(editTaskListener()));  
    
    QObject::connect(widget.checkBtn, SIGNAL(clicked()), this, SLOT(checkTaskListener()));  
}

editTaskWindow::~editTaskWindow() {
}


void editTaskWindow::editTaskListener() {
    
    
    editTask_->setTitre(widget.taskName->text().toStdString());
    
    editTask_->setOrdo(widget.checkBoxOrdo->isChecked());
    
    if(editTask_->isOrdo()) {
        editTask_->setNumber(widget.number->value());
    }
    
    editTask_->setEcheance(widget.checkBoxEcheance->isChecked());
    
    if(editTask_->isEcheance()) {
        editTask_->setDeadLine(widget.comboEcheance->currentText().toStdString());
    }
    else {
        editTask_->setDeadLine("");
    }
    
    parent_->updateViewTasksList();
    
    
    
}

void editTaskWindow::checkTaskListener() {
    
    editTask_->setCheck(!editTask_->isCheck());
    
    
    parent_->updateViewTasksList();
}